package com.game.battleship.data;


/**
 * this class is implemented with the default understanding that the fields index order
 * is the natural order of a table's fileds - from left to right , and from first row to the last.
 * The same default logic is used in {@link ShipCellsHolder}
 * @author vasil.konstantinov
 *
 */
public class BoardCell {
	
	/**
	 * x coordinate
	 */
	public int x;
	
	/**
	 * y coordinate
	 */
	public int y;

	/**
	 * 
	 * @param x
	 * @param y
	 */
	public BoardCell(int x, int y) {
		this.x = x;
		this.y = y;		
	}
	
	/**
	 * 
	 * @param index
	 * @param boardSideSize
	 * @return  BoardCell From Index
	 */
	public static BoardCell getBoardCellFromIndex(int index,int boardSideSize) {
		int x = index % boardSideSize;
		int y = index / boardSideSize;

		return new BoardCell(x, y);
	}

	/**
	 * 
	 * @param bf
	 * @param boardSideSize
	 * @return Position From BoardCell
	 */
	public static int getPositionFromBoardCell(BoardCell bf,int boardSideSize) {
		int position = bf.y * boardSideSize + bf.x;
		return position;
	}
}